<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>32.7. tokenize — Tokenizer for Python source &mdash; Python 3.4.3 documentation</title>
    
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.4.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 3.4.3 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python 3.4.3 documentation" href="../index.html" />
    <link rel="up" title="32. Python Language Services" href="language.html" />
    <link rel="next" title="32.8. tabnanny — Detection of ambiguous indentation" href="tabnanny.html" />
    <link rel="prev" title="32.6. keyword — Testing for Python keywords" href="keyword.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    <script type="text/javascript" src="../_static/version_switch.js"></script>
    
 

  </head>
  <body>  
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="tabnanny.html" title="32.8. tabnanny — Detection of ambiguous indentation"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="keyword.html" title="32.6. keyword — Testing for Python keywords"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">3.4.3</span>
          <a href="../index.html">Documentation</a> &raquo;
        </li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="language.html" accesskey="U">32. Python Language Services</a> &raquo;</li> 
      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-tokenize">
<span id="tokenize-tokenizer-for-python-source"></span><h1>32.7. <a class="reference internal" href="#module-tokenize" title="tokenize: Lexical scanner for Python source code."><tt class="xref py py-mod docutils literal"><span class="pre">tokenize</span></tt></a> &#8212; Tokenizer for Python source<a class="headerlink" href="#module-tokenize" title="Permalink to this headline">¶</a></h1>
<p><strong>Source code:</strong> <a class="reference external" href="https://hg.python.org/cpython/file/3.4/Lib/tokenize.py">Lib/tokenize.py</a></p>
<hr class="docutils" />
<p>The <a class="reference internal" href="#module-tokenize" title="tokenize: Lexical scanner for Python source code."><tt class="xref py py-mod docutils literal"><span class="pre">tokenize</span></tt></a> module provides a lexical scanner for Python source code,
implemented in Python.  The scanner in this module returns comments as tokens
as well, making it useful for implementing &#8220;pretty-printers,&#8221; including
colorizers for on-screen displays.</p>
<p>To simplify token stream handling, all <a class="reference internal" href="../reference/lexical_analysis.html#operators"><em>Operators</em></a> and <a class="reference internal" href="../reference/lexical_analysis.html#delimiters"><em>Delimiters</em></a>
tokens are returned using the generic <a class="reference internal" href="token.html#token.OP" title="token.OP"><tt class="xref py py-data docutils literal"><span class="pre">token.OP</span></tt></a> token type.  The exact
type can be determined by checking the <tt class="docutils literal"><span class="pre">exact_type</span></tt> property on the
<a class="reference internal" href="../glossary.html#term-named-tuple"><em class="xref std std-term">named tuple</em></a> returned from <a class="reference internal" href="#tokenize.tokenize" title="tokenize.tokenize"><tt class="xref py py-func docutils literal"><span class="pre">tokenize.tokenize()</span></tt></a>.</p>
<div class="section" id="tokenizing-input">
<h2>32.7.1. Tokenizing Input<a class="headerlink" href="#tokenizing-input" title="Permalink to this headline">¶</a></h2>
<p>The primary entry point is a <a class="reference internal" href="../glossary.html#term-generator"><em class="xref std std-term">generator</em></a>:</p>
<dl class="function">
<dt id="tokenize.tokenize">
<tt class="descclassname">tokenize.</tt><tt class="descname">tokenize</tt><big>(</big><em>readline</em><big>)</big><a class="headerlink" href="#tokenize.tokenize" title="Permalink to this definition">¶</a></dt>
<dd><p>The <a class="reference internal" href="#module-tokenize" title="tokenize: Lexical scanner for Python source code."><tt class="xref py py-func docutils literal"><span class="pre">tokenize()</span></tt></a> generator requires one argument, <em>readline</em>, which
must be a callable object which provides the same interface as the
<a class="reference internal" href="io.html#io.IOBase.readline" title="io.IOBase.readline"><tt class="xref py py-meth docutils literal"><span class="pre">io.IOBase.readline()</span></tt></a> method of file objects.  Each call to the
function should return one line of input as bytes.</p>
<p>The generator produces 5-tuples with these members: the token type; the
token string; a 2-tuple <tt class="docutils literal"><span class="pre">(srow,</span> <span class="pre">scol)</span></tt> of ints specifying the row and
column where the token begins in the source; a 2-tuple <tt class="docutils literal"><span class="pre">(erow,</span> <span class="pre">ecol)</span></tt> of
ints specifying the row and column where the token ends in the source; and
the line on which the token was found. The line passed (the last tuple item)
is the <em>logical</em> line; continuation lines are included.  The 5 tuple is
returned as a <a class="reference internal" href="../glossary.html#term-named-tuple"><em class="xref std std-term">named tuple</em></a> with the field names:
<tt class="docutils literal"><span class="pre">type</span> <span class="pre">string</span> <span class="pre">start</span> <span class="pre">end</span> <span class="pre">line</span></tt>.</p>
<p>The returned <a class="reference internal" href="../glossary.html#term-named-tuple"><em class="xref std std-term">named tuple</em></a> has a additional property named
<tt class="docutils literal"><span class="pre">exact_type</span></tt> that contains the exact operator type for
<a class="reference internal" href="token.html#token.OP" title="token.OP"><tt class="xref py py-data docutils literal"><span class="pre">token.OP</span></tt></a> tokens.  For all other token types <tt class="docutils literal"><span class="pre">exact_type</span></tt>
equals the named tuple <tt class="docutils literal"><span class="pre">type</span></tt> field.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.1: </span>Added support for named tuples.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 3.3: </span>Added support for <tt class="docutils literal"><span class="pre">exact_type</span></tt>.</p>
</div>
<p><a class="reference internal" href="#module-tokenize" title="tokenize: Lexical scanner for Python source code."><tt class="xref py py-func docutils literal"><span class="pre">tokenize()</span></tt></a> determines the source encoding of the file by looking for a
UTF-8 BOM or encoding cookie, according to <span class="target" id="index-0"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-0263"><strong>PEP 263</strong></a>.</p>
</dd></dl>

<p>All constants from the <a class="reference internal" href="token.html#module-token" title="token: Constants representing terminal nodes of the parse tree."><tt class="xref py py-mod docutils literal"><span class="pre">token</span></tt></a> module are also exported from
<a class="reference internal" href="#module-tokenize" title="tokenize: Lexical scanner for Python source code."><tt class="xref py py-mod docutils literal"><span class="pre">tokenize</span></tt></a>, as are three additional token type values:</p>
<dl class="data">
<dt id="tokenize.COMMENT">
<tt class="descclassname">tokenize.</tt><tt class="descname">COMMENT</tt><a class="headerlink" href="#tokenize.COMMENT" title="Permalink to this definition">¶</a></dt>
<dd><p>Token value used to indicate a comment.</p>
</dd></dl>

<dl class="data">
<dt id="tokenize.NL">
<tt class="descclassname">tokenize.</tt><tt class="descname">NL</tt><a class="headerlink" href="#tokenize.NL" title="Permalink to this definition">¶</a></dt>
<dd><p>Token value used to indicate a non-terminating newline.  The NEWLINE token
indicates the end of a logical line of Python code; NL tokens are generated
when a logical line of code is continued over multiple physical lines.</p>
</dd></dl>

<dl class="data">
<dt id="tokenize.ENCODING">
<tt class="descclassname">tokenize.</tt><tt class="descname">ENCODING</tt><a class="headerlink" href="#tokenize.ENCODING" title="Permalink to this definition">¶</a></dt>
<dd><p>Token value that indicates the encoding used to decode the source bytes
into text. The first token returned by <a class="reference internal" href="#module-tokenize" title="tokenize: Lexical scanner for Python source code."><tt class="xref py py-func docutils literal"><span class="pre">tokenize()</span></tt></a> will always be an
ENCODING token.</p>
</dd></dl>

<p>Another function is provided to reverse the tokenization process. This is
useful for creating tools that tokenize a script, modify the token stream, and
write back the modified script.</p>
<dl class="function">
<dt id="tokenize.untokenize">
<tt class="descclassname">tokenize.</tt><tt class="descname">untokenize</tt><big>(</big><em>iterable</em><big>)</big><a class="headerlink" href="#tokenize.untokenize" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts tokens back into Python source code.  The <em>iterable</em> must return
sequences with at least two elements, the token type and the token string.
Any additional sequence elements are ignored.</p>
<p>The reconstructed script is returned as a single string.  The result is
guaranteed to tokenize back to match the input so that the conversion is
lossless and round-trips are assured.  The guarantee applies only to the
token type and token string as the spacing between tokens (column
positions) may change.</p>
<p>It returns bytes, encoded using the ENCODING token, which is the first
token sequence output by <a class="reference internal" href="#module-tokenize" title="tokenize: Lexical scanner for Python source code."><tt class="xref py py-func docutils literal"><span class="pre">tokenize()</span></tt></a>.</p>
</dd></dl>

<p><a class="reference internal" href="#module-tokenize" title="tokenize: Lexical scanner for Python source code."><tt class="xref py py-func docutils literal"><span class="pre">tokenize()</span></tt></a> needs to detect the encoding of source files it tokenizes. The
function it uses to do this is available:</p>
<dl class="function">
<dt id="tokenize.detect_encoding">
<tt class="descclassname">tokenize.</tt><tt class="descname">detect_encoding</tt><big>(</big><em>readline</em><big>)</big><a class="headerlink" href="#tokenize.detect_encoding" title="Permalink to this definition">¶</a></dt>
<dd><p>The <a class="reference internal" href="#tokenize.detect_encoding" title="tokenize.detect_encoding"><tt class="xref py py-func docutils literal"><span class="pre">detect_encoding()</span></tt></a> function is used to detect the encoding that
should be used to decode a Python source file. It requires one argument,
readline, in the same way as the <a class="reference internal" href="#module-tokenize" title="tokenize: Lexical scanner for Python source code."><tt class="xref py py-func docutils literal"><span class="pre">tokenize()</span></tt></a> generator.</p>
<p>It will call readline a maximum of twice, and return the encoding used
(as a string) and a list of any lines (not decoded from bytes) it has read
in.</p>
<p>It detects the encoding from the presence of a UTF-8 BOM or an encoding
cookie as specified in <span class="target" id="index-1"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-0263"><strong>PEP 263</strong></a>. If both a BOM and a cookie are present,
but disagree, a SyntaxError will be raised. Note that if the BOM is found,
<tt class="docutils literal"><span class="pre">'utf-8-sig'</span></tt> will be returned as an encoding.</p>
<p>If no encoding is specified, then the default of <tt class="docutils literal"><span class="pre">'utf-8'</span></tt> will be
returned.</p>
<p>Use <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> to open Python source files: it uses
<a class="reference internal" href="#tokenize.detect_encoding" title="tokenize.detect_encoding"><tt class="xref py py-func docutils literal"><span class="pre">detect_encoding()</span></tt></a> to detect the file encoding.</p>
</dd></dl>

<dl class="function">
<dt id="tokenize.open">
<tt class="descclassname">tokenize.</tt><tt class="descname">open</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#tokenize.open" title="Permalink to this definition">¶</a></dt>
<dd><p>Open a file in read only mode using the encoding detected by
<a class="reference internal" href="#tokenize.detect_encoding" title="tokenize.detect_encoding"><tt class="xref py py-func docutils literal"><span class="pre">detect_encoding()</span></tt></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.2.</span></p>
</div>
</dd></dl>

<dl class="exception">
<dt id="tokenize.TokenError">
<em class="property">exception </em><tt class="descclassname">tokenize.</tt><tt class="descname">TokenError</tt><a class="headerlink" href="#tokenize.TokenError" title="Permalink to this definition">¶</a></dt>
<dd><p>Raised when either a docstring or expression that may be split over several
lines is not completed anywhere in the file, for example:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="s">&quot;&quot;&quot;Beginning of</span>
<span class="s">docstring</span>
</pre></div>
</div>
<p>or:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="p">[</span><span class="mi">1</span><span class="p">,</span>
 <span class="mi">2</span><span class="p">,</span>
 <span class="mi">3</span>
</pre></div>
</div>
</dd></dl>

<p>Note that unclosed single-quoted strings do not cause an error to be
raised. They are tokenized as <tt class="docutils literal"><span class="pre">ERRORTOKEN</span></tt>, followed by the tokenization of
their contents.</p>
</div>
<div class="section" id="command-line-usage">
<span id="tokenize-cli"></span><h2>32.7.2. Command-Line Usage<a class="headerlink" href="#command-line-usage" title="Permalink to this headline">¶</a></h2>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
<p>The <a class="reference internal" href="#module-tokenize" title="tokenize: Lexical scanner for Python source code."><tt class="xref py py-mod docutils literal"><span class="pre">tokenize</span></tt></a> module can be executed as a script from the command line.
It is as simple as:</p>
<div class="highlight-sh"><div class="highlight"><pre>python -m tokenize <span class="o">[</span>-e<span class="o">]</span> <span class="o">[</span>filename.py<span class="o">]</span>
</pre></div>
</div>
<p>The following options are accepted:</p>
<dl class="cmdoption">
<dt id="cmdoption-tokenize-h">
<span id="cmdoption-tokenize--help"></span><tt class="descname">-h</tt><tt class="descclassname"></tt><tt class="descclassname">, </tt><tt class="descname">--help</tt><tt class="descclassname"></tt><a class="headerlink" href="#cmdoption-tokenize-h" title="Permalink to this definition">¶</a></dt>
<dd><p>show this help message and exit</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-tokenize-e">
<span id="cmdoption-tokenize--exact"></span><tt class="descname">-e</tt><tt class="descclassname"></tt><tt class="descclassname">, </tt><tt class="descname">--exact</tt><tt class="descclassname"></tt><a class="headerlink" href="#cmdoption-tokenize-e" title="Permalink to this definition">¶</a></dt>
<dd><p>display token names using the exact type</p>
</dd></dl>

<p>If <tt class="file docutils literal"><span class="pre">filename.py</span></tt> is specified its contents are tokenized to stdout.
Otherwise, tokenization is performed on stdin.</p>
</div>
<div class="section" id="examples">
<h2>32.7.3. Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
<p>Example of a script rewriter that transforms float literals into Decimal
objects:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">tokenize</span> <span class="k">import</span> <span class="n">tokenize</span><span class="p">,</span> <span class="n">untokenize</span><span class="p">,</span> <span class="n">NUMBER</span><span class="p">,</span> <span class="n">STRING</span><span class="p">,</span> <span class="n">NAME</span><span class="p">,</span> <span class="n">OP</span>
<span class="kn">from</span> <span class="nn">io</span> <span class="k">import</span> <span class="n">BytesIO</span>

<span class="k">def</span> <span class="nf">decistmt</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Substitute Decimals for floats in a string of statements.</span>

<span class="sd">    &gt;&gt;&gt; from decimal import Decimal</span>
<span class="sd">    &gt;&gt;&gt; s = &#39;print(+21.3e-5*-.1234/81.7)&#39;</span>
<span class="sd">    &gt;&gt;&gt; decistmt(s)</span>
<span class="sd">    &quot;print (+Decimal (&#39;21.3e-5&#39;)*-Decimal (&#39;.1234&#39;)/Decimal (&#39;81.7&#39;))&quot;</span>

<span class="sd">    The format of the exponent is inherited from the platform C library.</span>
<span class="sd">    Known cases are &quot;e-007&quot; (Windows) and &quot;e-07&quot; (not Windows).  Since</span>
<span class="sd">    we&#39;re only showing 12 digits, and the 13th isn&#39;t close to 5, the</span>
<span class="sd">    rest of the output should be platform-independent.</span>

<span class="sd">    &gt;&gt;&gt; exec(s) #doctest: +ELLIPSIS</span>
<span class="sd">    -3.21716034272e-0...7</span>

<span class="sd">    Output from calculations with Decimal should be identical across all</span>
<span class="sd">    platforms.</span>

<span class="sd">    &gt;&gt;&gt; exec(decistmt(s))</span>
<span class="sd">    -3.217160342717258261933904529E-7</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">g</span> <span class="o">=</span> <span class="n">tokenize</span><span class="p">(</span><span class="n">BytesIO</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s">&#39;utf-8&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">readline</span><span class="p">)</span> <span class="c"># tokenize the string</span>
    <span class="k">for</span> <span class="n">toknum</span><span class="p">,</span> <span class="n">tokval</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span>  <span class="ow">in</span> <span class="n">g</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">toknum</span> <span class="o">==</span> <span class="n">NUMBER</span> <span class="ow">and</span> <span class="s">&#39;.&#39;</span> <span class="ow">in</span> <span class="n">tokval</span><span class="p">:</span>  <span class="c"># replace NUMBER tokens</span>
            <span class="n">result</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span>
                <span class="p">(</span><span class="n">NAME</span><span class="p">,</span> <span class="s">&#39;Decimal&#39;</span><span class="p">),</span>
                <span class="p">(</span><span class="n">OP</span><span class="p">,</span> <span class="s">&#39;(&#39;</span><span class="p">),</span>
                <span class="p">(</span><span class="n">STRING</span><span class="p">,</span> <span class="nb">repr</span><span class="p">(</span><span class="n">tokval</span><span class="p">)),</span>
                <span class="p">(</span><span class="n">OP</span><span class="p">,</span> <span class="s">&#39;)&#39;</span><span class="p">)</span>
            <span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">toknum</span><span class="p">,</span> <span class="n">tokval</span><span class="p">))</span>
    <span class="k">return</span> <span class="n">untokenize</span><span class="p">(</span><span class="n">result</span><span class="p">)</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s">&#39;utf-8&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Example of tokenizing from the command line.  The script:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="k">def</span> <span class="nf">say_hello</span><span class="p">():</span>
    <span class="nb">print</span><span class="p">(</span><span class="s">&quot;Hello, World!&quot;</span><span class="p">)</span>

<span class="n">say_hello</span><span class="p">()</span>
</pre></div>
</div>
<p>will be tokenized to the following output where the first column is the range
of the line/column coordinates where the token is found, the second column is
the name of the token, and the final column is the value of the token (if any)</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="nv">$ </span>python -m tokenize hello.py
0,0-0,0:            ENCODING       <span class="s1">&#39;utf-8&#39;</span>
1,0-1,3:            NAME           <span class="s1">&#39;def&#39;</span>
1,4-1,13:           NAME           <span class="s1">&#39;say_hello&#39;</span>
1,13-1,14:          OP             <span class="s1">&#39;(&#39;</span>
1,14-1,15:          OP             <span class="s1">&#39;)&#39;</span>
1,15-1,16:          OP             <span class="s1">&#39;:&#39;</span>
1,16-1,17:          NEWLINE        <span class="s1">&#39;\n&#39;</span>
2,0-2,4:            INDENT         <span class="s1">&#39;    &#39;</span>
2,4-2,9:            NAME           <span class="s1">&#39;print&#39;</span>
2,9-2,10:           OP             <span class="s1">&#39;(&#39;</span>
2,10-2,25:          STRING         <span class="s1">&#39;&quot;Hello, World!&quot;&#39;</span>
2,25-2,26:          OP             <span class="s1">&#39;)&#39;</span>
2,26-2,27:          NEWLINE        <span class="s1">&#39;\n&#39;</span>
3,0-3,1:            NL             <span class="s1">&#39;\n&#39;</span>
4,0-4,0:            DEDENT         <span class="s1">&#39;&#39;</span>
4,0-4,9:            NAME           <span class="s1">&#39;say_hello&#39;</span>
4,9-4,10:           OP             <span class="s1">&#39;(&#39;</span>
4,10-4,11:          OP             <span class="s1">&#39;)&#39;</span>
4,11-4,12:          NEWLINE        <span class="s1">&#39;\n&#39;</span>
5,0-5,0:            ENDMARKER      <span class="s1">&#39;&#39;</span>
</pre></div>
</div>
<p>The exact token type names can be displayed using the <tt class="docutils literal"><span class="pre">-e</span></tt> option:</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="nv">$ </span>python -m tokenize -e hello.py
0,0-0,0:            ENCODING       <span class="s1">&#39;utf-8&#39;</span>
1,0-1,3:            NAME           <span class="s1">&#39;def&#39;</span>
1,4-1,13:           NAME           <span class="s1">&#39;say_hello&#39;</span>
1,13-1,14:          LPAR           <span class="s1">&#39;(&#39;</span>
1,14-1,15:          RPAR           <span class="s1">&#39;)&#39;</span>
1,15-1,16:          COLON          <span class="s1">&#39;:&#39;</span>
1,16-1,17:          NEWLINE        <span class="s1">&#39;\n&#39;</span>
2,0-2,4:            INDENT         <span class="s1">&#39;    &#39;</span>
2,4-2,9:            NAME           <span class="s1">&#39;print&#39;</span>
2,9-2,10:           LPAR           <span class="s1">&#39;(&#39;</span>
2,10-2,25:          STRING         <span class="s1">&#39;&quot;Hello, World!&quot;&#39;</span>
2,25-2,26:          RPAR           <span class="s1">&#39;)&#39;</span>
2,26-2,27:          NEWLINE        <span class="s1">&#39;\n&#39;</span>
3,0-3,1:            NL             <span class="s1">&#39;\n&#39;</span>
4,0-4,0:            DEDENT         <span class="s1">&#39;&#39;</span>
4,0-4,9:            NAME           <span class="s1">&#39;say_hello&#39;</span>
4,9-4,10:           LPAR           <span class="s1">&#39;(&#39;</span>
4,10-4,11:          RPAR           <span class="s1">&#39;)&#39;</span>
4,11-4,12:          NEWLINE        <span class="s1">&#39;\n&#39;</span>
5,0-5,0:            ENDMARKER      <span class="s1">&#39;&#39;</span>
</pre></div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">32.7. <tt class="docutils literal"><span class="pre">tokenize</span></tt> &#8212; Tokenizer for Python source</a><ul>
<li><a class="reference internal" href="#tokenizing-input">32.7.1. Tokenizing Input</a></li>
<li><a class="reference internal" href="#command-line-usage">32.7.2. Command-Line Usage</a></li>
<li><a class="reference internal" href="#examples">32.7.3. Examples</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="keyword.html"
                        title="previous chapter">32.6. <tt class="docutils literal"><span class="pre">keyword</span></tt> &#8212; Testing for Python keywords</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="tabnanny.html"
                        title="next chapter">32.8. <tt class="docutils literal"><span class="pre">tabnanny</span></tt> &#8212; Detection of ambiguous indentation</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/library/tokenize.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="tabnanny.html" title="32.8. tabnanny — Detection of ambiguous indentation"
             >next</a> |</li>
        <li class="right" >
          <a href="keyword.html" title="32.6. keyword — Testing for Python keywords"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">3.4.3</span>
          <a href="../index.html">Documentation</a> &raquo;
        </li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="language.html" >32. Python Language Services</a> &raquo;</li> 
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2015, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Feb 26, 2015.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2.3.
    </div>

  </body>
</html>